import { createDiscreteApi } from "naive-ui";
const {message} = createDiscreteApi(["message"]);
//在这里二次封装axios
//创建实例
//配置请求,响应拦截器
import axios from 'axios'
import store from '../store/index'
//请求示例
const request = axios.create({
    baseURL:'http://localhost:3001',
    timeout:1000,
});
//配置请求和响应拦截器
request.interceptors.request.use(
    //成功的请求
    (req)=>{
        req.headers.token = store.getters["user/getToken"];
        return req;
    },
    //失败的情qiu 
    (error)=>{
        return Promise.reject(error)
    }
)
request.interceptors.response.use(
    //成功响应的
    (res)=>{
        //将res里面的data解构处理
        const {data} = res;
        if(data.code== '200'){
            message.success(data.message)
        }else{
            message.error(data.message)
        }
        return data;
    },
    //失败的响应
    (error)=>{
		return Promise.reject(error)
	}
)
//暴露出去
export default request